package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Applicant;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import forms.*;

import db.DbException;

public class AddressSubmitAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws DbException {
		HttpSession session = request.getSession();
		
		Applicant applicant = (Applicant) session.getAttribute("applicant");
		
		AddressSubmitForm iForm = (AddressSubmitForm) form;
		
		if(applicant.isDomestic()){
			applicant.setAddress(iForm.getStreet(), iForm.getCity(), iForm.getState(), ((Integer)iForm.getZipCode()).toString(), ((Integer)iForm.getCountryTelephoneCode()).toString(), ((Integer)iForm.getAreaCode()).toString(), iForm.getPhoneNumber());
			applicant.setState(iForm.getState());
		}else{
			applicant.setAddress(iForm.getStreet(), iForm.getCity(), iForm.getState(), ((Integer)iForm.getZipCode()).toString(), ((Integer)iForm.getCountryTelephoneCode()).toString(), ((Integer)iForm.getAreaCode()).toString(), iForm.getPhoneNumber());
			//applicant.setDomestic(false);
			
		}
		
		
		session.setAttribute("applicant", applicant);
		
		return mapping.findForward("success");

	}
}

